package com.zhsm.fuxi.mvp.presenter

import com.hankkin.library.mvp.presenter.RxLifePresenter
import com.hankkin.reading.http.HttpClientUtils
import com.zhsm.fuxi.mvp.contract.InvoiceGiveContract
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

/**
 * Created by GuZhC on 2018/10/9.
 * describe:
 */
class InvoiceGivePresenter : RxLifePresenter<InvoiceGiveContract.IView>(), InvoiceGiveContract.IPresenter {

     override fun buildInvoice(map: HashMap<String, Any>) {
         getMvpView().showLoding()
        HttpClientUtils.Builder.getPaipiaHttp().buildInvoice(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeEx({
                    getMvpView().hideLoding()
                    getMvpView().buildInvoiceSucess(it)
                }, {
                    getMvpView().hideLoding()
                }).bindRxLifeEx(RxLife.ON_DESTROY)
    }

    override fun getInvoiceMoney(orders: String) {
        getMvpView().showLoding()
        val map = HashMap<String, Any>()
        map["orderIds"] = orders
        HttpClientUtils.Builder.getPaipiaHttp().getInvoiceMoney(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeEx({
                    getMvpView().hideLoding()
                    getMvpView().setMoney(it,true)
                }, {
                    getMvpView().hideLoding()
                    getMvpView().setMoney("获取失败，点击重试",false)
                }).bindRxLifeEx(RxLife.ON_DESTROY)
    }
}